﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="evk_seotud_kanne", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(EvkSeotudKanne))]
    public class EvkSeotudKanneSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IEvkSeotudKanne clazz;
        
        public EvkSeotudKanneSerializer(IEvkSeotudKanne clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ariregistri_kood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.AriregistriKood))).ToString());
            Writer.WriteEndElement();
            if (clazz.EsmakandeAeg!=null) {
                Writer.WriteStartElement("esmakande_aeg");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.EsmakandeAeg))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeAeg!=null) {
                Writer.WriteStartElement("kande_aeg");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.KandeAeg))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeliigiTahis!=null) {
                Writer.WriteStartElement("kandeliigi_tahis");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandeliigiTahis))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeNr!=null) {
                Writer.WriteStartElement("kande_nr");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.KandeNr))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.NotaritehinguKood!=null) {
                Writer.WriteStartElement("notaritehingu_kood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.NotaritehinguKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Arinimi!=null) {
                Writer.WriteStartElement("arinimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Arinimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OiguslikuVormiTahis!=null) {
                Writer.WriteStartElement("oigusliku_vormi_tahis");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OiguslikuVormiTahis))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LoppstaatuseTahis!=null) {
                Writer.WriteStartElement("loppstaatuse_tahis");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LoppstaatuseTahis))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kapital!=null) {
                Writer.WriteStartElement("kapital");
                global::Xtee.Core.SerializationMetadata metaKapital = this.GetMetaData(clazz.Kapital);
                Writer.WriteTypeAttribute(metaKapital.TypeQualifiedName.Namespace, metaKapital.TypeQualifiedName.Name);
                metaKapital.NewSerializer(clazz.Kapital).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            for (int x = 0; ((clazz.Pohikiri != null) 
                        && (x < clazz.Pohikiri.Count)); x = (x + 1)) {
                if (clazz.Pohikiri[x]!=null) {
                    Writer.WriteStartElement("pohikiri");
                    global::Xtee.Core.SerializationMetadata metaPohikiri = this.GetMetaData(clazz.Pohikiri[x]);
                    Writer.WriteTypeAttribute(metaPohikiri.TypeQualifiedName.Namespace, metaPohikiri.TypeQualifiedName.Name);
                    metaPohikiri.NewSerializer(clazz.Pohikiri[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ariregistri_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>evk_seotud_kanne>ariregistri_kood");
                }
                clazz.AriregistriKood = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("ariregistri_kood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>evk_seotud_kanne>ariregistri_kood", Reader.LocalName);
            }
            if (Reader.LocalName=="esmakande_aeg") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>evk_seotud_kanne>esmakande_aeg");
                }
                clazz.EsmakandeAeg = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("esmakande_aeg")).Value;
            }
            if (Reader.LocalName=="kande_aeg") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>evk_seotud_kanne>kande_aeg");
                }
                clazz.KandeAeg = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("kande_aeg")).Value;
            }
            if (Reader.LocalName=="kandeliigi_tahis") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>evk_seotud_kanne>kandeliigi_tahis");
                }
                clazz.KandeliigiTahis = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kandeliigi_tahis")).Value;
            }
            if (Reader.LocalName=="kande_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>evk_seotud_kanne>kande_nr");
                }
                clazz.KandeNr = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("kande_nr")).Value;
            }
            if (Reader.LocalName=="notaritehingu_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>evk_seotud_kanne>notaritehingu_kood");
                }
                clazz.NotaritehinguKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("notaritehingu_kood")).Value;
            }
            if (Reader.LocalName=="arinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>evk_seotud_kanne>arinimi");
                }
                clazz.Arinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("arinimi")).Value;
            }
            if (Reader.LocalName=="oigusliku_vormi_tahis") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>evk_seotud_kanne>oigusliku_vormi_tahis");
                }
                clazz.OiguslikuVormiTahis = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("oigusliku_vormi_tahis")).Value;
            }
            if (Reader.LocalName=="loppstaatuse_tahis") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>evk_seotud_kanne>loppstaatuse_tahis");
                }
                clazz.LoppstaatuseTahis = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("loppstaatuse_tahis")).Value;
            }
            if (Reader.LocalName=="kapital") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>evk_seotud_kanne>kapital");
                }
                global::Xtee.Core.SerializationMetadata metaKapital = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEvkKapital>(Reader, "evk_kapital", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Kapital = metaKapital.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEvkKapital>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("kapital");
                    metaKapital.NewSerializer(clazz.Kapital).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="pohikiri") {
                clazz.Pohikiri = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEvkPohikiri>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "pohikiri")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>evk_seotud_kanne>pohikiri");
                    }
                    global::Xtee.Core.SerializationMetadata metaPohikiri = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEvkPohikiri>(Reader, "evk_pohikiri", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEvkPohikiri item = metaPohikiri.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEvkPohikiri>();
                    clazz.Pohikiri.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("pohikiri");
                        metaPohikiri.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
